﻿using Acme.BookStore2.Localization;
using Volo.Abp.AuditLogging.Localization;
using Volo.Abp.Authorization.Permissions;
using Volo.Abp.Identity;
using Volo.Abp.Identity.Localization;
using Volo.Abp.Localization;

namespace Acme.BookStore2.Permissions
{
    public class BookStore2PermissionDefinitionProvider : PermissionDefinitionProvider
    {
        public override void Define(IPermissionDefinitionContext context)
        {
            var myGroup = context.AddGroup(BookStore2Permissions.GroupName);           
            var identityGroup = context.GetGroup(IdentityPermissions.GroupName);
            var auditGroup = context.AddGroup("AbpAuditLogging");
            
            //组织
            var organizationUnitsPermission = identityGroup.AddPermission(BookStore2Permissions.OrganizationUnits.Default, IdentityL("Permission:OrganizationUnitManagement"));
            organizationUnitsPermission.AddChild(BookStore2Permissions.OrganizationUnits.ManageOU, IdentityL("Permission:ManageOU"));
            organizationUnitsPermission.AddChild(BookStore2Permissions.OrganizationUnits.ManageMembers, IdentityL("Permission:ManageUsers"));
            organizationUnitsPermission.AddChild(BookStore2Permissions.OrganizationUnits.ManageRoles, IdentityL("Permission:ManageRoles"));

            //声明类型
            var claimPermission = identityGroup.AddPermission(BookStore2Permissions.ClaimTypes.Default, IdentityL("Permission:ClaimManagement"));
            claimPermission.AddChild(BookStore2Permissions.ClaimTypes.Create, IdentityL("Permission:Create"));
            claimPermission.AddChild(BookStore2Permissions.ClaimTypes.Update, IdentityL("Permission:Edit"));
            claimPermission.AddChild(BookStore2Permissions.ClaimTypes.Delete, IdentityL("Permission:Delete"));

            //审计日志
            var auditLogPermission = auditGroup.AddPermission(BookStore2Permissions.AuditLogging.Default, AuditLoggingL("Permission:AuditLogging"));
            
            //安全日志
            // var securityLogPermission = identityGroup.AddPermission(BookStore2Permissions.SecurityLog.Default, L("Permission:SecurityLog"));
            // securityLogPermission.AddChild(BookStore2Permissions.SecurityLog.List, L("Permission:SecurityLog.List"));
            
            //车辆
            var vehiclePermission = myGroup.AddPermission(BookStore2Permissions.Vehicle.Default, IdentityL("Permission:Vehicle"));
            vehiclePermission.AddChild(BookStore2Permissions.Vehicle.Create, IdentityL("Permission:Create"));
            vehiclePermission.AddChild(BookStore2Permissions.Vehicle.Update, IdentityL("Permission:Edit"));
            vehiclePermission.AddChild(BookStore2Permissions.Vehicle.Delete, IdentityL("Permission:Delete"));
            vehiclePermission.AddChild(BookStore2Permissions.Vehicle.Maintenance, IdentityL("Permission:Maintenance"));

            var vehicleDriveRecordPermission = vehiclePermission.AddChild(BookStore2Permissions.VehicleDriveRecord.Default,  IdentityL("Permission:VehicleDriveRecord"));
            vehicleDriveRecordPermission.AddChild(BookStore2Permissions.VehicleDriveRecord.Create, IdentityL("Permission:Create"));
            vehicleDriveRecordPermission.AddChild(BookStore2Permissions.VehicleDriveRecord.Update, IdentityL("Permission:Edit"));
            vehicleDriveRecordPermission.AddChild(BookStore2Permissions.VehicleDriveRecord.Delete, IdentityL("Permission:Delete"));
            
            var vehicleInspectionRecordPermission = vehiclePermission.AddChild(BookStore2Permissions.VehicleInspectionRecord.Default,  IdentityL("Permission:VehicleInspectionRecord"));
            vehicleInspectionRecordPermission.AddChild(BookStore2Permissions.VehicleInspectionRecord.Create, IdentityL("Permission:Create"));
            vehicleInspectionRecordPermission.AddChild(BookStore2Permissions.VehicleInspectionRecord.Update, IdentityL("Permission:Edit"));
            vehicleInspectionRecordPermission.AddChild(BookStore2Permissions.VehicleInspectionRecord.Delete, IdentityL("Permission:Delete"));
            
            var vehicleMaintenanceRecordPermission = vehiclePermission.AddChild(BookStore2Permissions.VehicleMaintenanceRecord.Default,  IdentityL("Permission:VehicleMaintenanceRecord"));
            vehicleMaintenanceRecordPermission.AddChild(BookStore2Permissions.VehicleMaintenanceRecord.Create, IdentityL("Permission:Create"));
            vehicleMaintenanceRecordPermission.AddChild(BookStore2Permissions.VehicleMaintenanceRecord.Update, IdentityL("Permission:Edit"));
            vehicleMaintenanceRecordPermission.AddChild(BookStore2Permissions.VehicleMaintenanceRecord.Delete, IdentityL("Permission:Delete"));
            
            var vehicleRepairRecordPermission = vehiclePermission.AddChild(BookStore2Permissions.VehicleRepairRecord.Default,  IdentityL("Permission:VehicleRepairRecord"));
            vehicleRepairRecordPermission.AddChild(BookStore2Permissions.VehicleRepairRecord.Create, IdentityL("Permission:Create"));
            vehicleRepairRecordPermission.AddChild(BookStore2Permissions.VehicleRepairRecord.Update, IdentityL("Permission:Edit"));
            vehicleRepairRecordPermission.AddChild(BookStore2Permissions.VehicleRepairRecord.Delete, IdentityL("Permission:Delete"));
        }

        private static LocalizableString L(string name)
        {
            return LocalizableString.Create<BookStore2Resource>(name);
        }
        
        private static LocalizableString IdentityL(string name)
        {
            return LocalizableString.Create<IdentityResource>(name);
        }

        private static LocalizableString AuditLoggingL(string name)
        {
            return LocalizableString.Create<AuditLoggingResource>(name);
        }
    }
}
